package felix.rule.api;

import felix.rule.data.msg.EngineMsg;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.function.Consumer;

@Data
@AllArgsConstructor
public final class TransactionTask {

    private final EngineMsg msg;
    private final Consumer<EngineMsg> onStart;
    private final Consumer<EngineMsg> onEnd;
    private final Consumer<Throwable> onFailure;
    private final long duration;
    private final long expirationTime;

    private boolean isCompleted;

    public TransactionTask(EngineMsg msg, Consumer<EngineMsg> onStart, Consumer<EngineMsg> onEnd, Consumer<Throwable> onFailure, long duration) {
        this.msg = msg;
        this.onStart = onStart;
        this.onEnd = onEnd;
        this.onFailure = onFailure;
        this.duration = duration;
        this.expirationTime = System.currentTimeMillis() + duration;
        this.isCompleted = false;
    }
}
